<?php
namespace app\admin\controller\rider;
use think\Db;
class Cash extends \app\admin\controller\Common
{
    public function index(){
        return view();
    }

    public function list(){
        $limit = request()->param('limit') ?? 15;
        $page = request()->param('page');
        $page = $page ? ($page - 1) * $limit : 0;
        $search = request()->param();
        $query = (new \app\common\model\RiderCash())
                    ->alias('cash')
                    ->join("{$this->tdb}rider rider","rider.id = cash.rider_id")
                    ->field(['cash.*'])
                    ->append(['addtime_text','agent_name','status_text','rider_name']);

        isset($search['rider_name']) && $search['rider_name'] != "" ? $query->where("rider.title like '%{$search['rider_name']}%'") : '';

        $query->order("cash.id desc");
        $list = $query->limit($page, $limit)->select();
        $count = $query->count();
   
        return self::successResult('',$list,$count);
    }


    public function info(){
        $id = $this->request->param('id');
        $info = (new \app\common\model\RiderCash())->where(['id' => $id])->find();
        $this->assign("info",$info);
        return view();
    }

    public function status(){
        $id = $this->request->param('id');
        $audit = $this->request->param('audit');
        $refuse_remarks = $this->request->param('status_fail');
        if($audit == "yes"){
            $update = [
                'status' => 2,
                'update_time' => time(),
            ];
        }
        if($audit == "no"){
            $update = [
                'status' => 1,
                'update_time' => time(),
                'refuse_remarks' => $refuse_remarks,
            ];
        }
        (new \app\common\model\RiderCash())->where(['id' => $id])->update($update);
        return self::successResult();
    }
  

 
}
